/*
	独立邮件发送
*/

var adminLoginedInfo = Cookies.getJSON('kplus_ad_logined_info');

function DomInit(){
	var ajaxData = { aId: adminLoginedInfo.aId, aToken: adminLoginedInfo.aToken };

	var WEditor = window.wangEditor, editorHtml = new WEditor('#html');
	editorHtml.create();

	this.sendEmail = function(data){
		/*
			@发送邮件
		*/
		var loadIndex = layer.load(1, { shade: [0.5, '#000'] });
		var _ajaxData = $.extend(ajaxData, data, {html: editorHtml.txt.html()});

		$.ajax({
			url: BASE_SERVICEURL + URlS.sys_email,
			type: 'POST',
			data: _ajaxData,
			success: function(responseData){
				
				if(responseData.msg.code == 200){
					//console.log(responseData);
					if(responseData.data.code === 200){
						layer.msg("发送邮件成功！", {time: 2000, end: function(){
							window.location.reload();
						}})
					}
					layer.close(loadIndex);
				}else{
					layer.close(loadIndex);
					layer.msg(MESSAGES.get_form_error + responseData.msg.msg, {time: 2000});
				}
			},
			error: function(responseData){
				layer.msg(MESSAGES.service_error, {time: 2000, end:function(){
					//导向500页面
					location.href = './500.html';
				}});
			}
		});
	}
}

$(function(){
	layui.use(['layer', 'form', 'table'], function(){
		var layer = layui.layer, form = layui.form, table = layui.table;

		var dom_init = new DomInit();

		form.on('submit(sendEmail)', function(data){
			//console.log(data)
			var f = data.field;
			dom_init.sendEmail({
				sign: 's', // 独立发送 固定填入
				title: f.title,
				uMail: f.email
			})
			return false;
		});
	})
})













